Skip to content

Conversation

@mormubis
Copy link
Contributor

@mormubis mormubis commented Oct 6, 2025

Motivation

The initial implementation of Worker E2E tests was somewhat tied to our specific use case and will not scale if we need to test different scenarios within the Worker environment.

Changes

It introduces a version of withWorker that automatically sets up the logs inside the worker. We can also pass an implementation, similar to what we do with withLogs and withBody.

Test instructions

All e2e still passed.

Checklist

  • Tested locally
  • Tested on staging
  • Added unit tests for this change.
  • Added e2e/integration tests for this change.

@cit-pr-commenter
Copy link

cit-pr-commenter bot commented Oct 6, 2025

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 162.96 KiB 162.96 KiB 0 B 0.00%
Rum Recorder 19.78 KiB 19.78 KiB 0 B 0.00%
Rum Profiler 4.89 KiB 4.89 KiB 0 B 0.00%
Logs 56.62 KiB 56.62 KiB 0 B 0.00%
Flagging 944 B 944 B 0 B 0.00%
Rum Slim 119.90 KiB 119.90 KiB 0 B 0.00%
Worker 23.60 KiB 23.60 KiB 0 B 0.00%
🚀 CPU Performance
Action Name Base CPU Time (ms) Local CPU Time (ms) 𝚫%
RUM - add global context 0.0041 0.0041 0.00%
RUM - add action 0.0132 0.0118 -10.61%
RUM - add error 0.0132 0.0121 -8.33%
RUM - add timing 0.003 0.0027 -10.00%
RUM - start view 0.0038 0.0032 -15.79%
RUM - start/stop session replay recording 0.0006 0.0007 +16.67%
Logs - log message 0.0134 0.0131 -2.24%
🧠 Memory Performance
Action Name Base Memory Consumption Local Memory Consumption 𝚫
RUM - add global context 25.79 KiB 25.95 KiB +173 B
RUM - add action 47.16 KiB 46.11 KiB -1.06 KiB
RUM - add timing 24.44 KiB 24.59 KiB +155 B
RUM - add error 52.34 KiB 50.47 KiB -1.87 KiB
RUM - start/stop session replay recording 23.46 KiB 24.16 KiB +718 B
RUM - start view 423.98 KiB 429.77 KiB +5.79 KiB
Logs - log message 43.09 KiB 42.85 KiB -242 B

🔗 RealWorld

@datadog-official
Copy link

datadog-official bot commented Oct 6, 2025

✅ Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

🎯 Code Coverage
Patch Coverage: 100.00%
Total Coverage: 92.64% (+0.00%)

View detailed report

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 1ea0c00 | Docs | Datadog PR Page | Was this helpful? Give us feedback!

@mormubis mormubis marked this pull request as ready for review October 6, 2025 12:56
@mormubis mormubis requested a review from a team as a code owner October 6, 2025 12:56
@mormubis mormubis changed the title refactor: change e2e implementation for workers 👷 change e2e implementation for workers Oct 6, 2025
@mormubis mormubis force-pushed the adlrb/logs-improve-testing branch from 0feb678 to a5b8ded Compare October 10, 2025 09:18
@mormubis mormubis force-pushed the adlrb/logs-improve-testing branch from 9afa674 to 3be6403 Compare October 15, 2025 08:44
@mormubis mormubis requested a review from bcaudan October 15, 2025 15:07
@mormubis mormubis force-pushed the adlrb/logs-improve-testing branch from 3d6c391 to 4a69138 Compare October 22, 2025 08:36
@mormubis mormubis requested a review from bcaudan October 22, 2025 08:47
export function workerSetup(options: WorkerOptions, servers: Servers) {
return js`
${options.importScripts ? js`importScripts('/datadog-logs.js');` : js`import '/datadog-logs.js';`}
export function workerSetup(options: SetupOptions, servers: Servers) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭 thought: ‏as this helper is not really related to the page setup, maybe we could move it to createTest to colocate it with other worker setup code and avoid the back and forth between those files.

navigator.serviceWorker.register('/sw.js', ${JSON.stringify(options)}).then((registration) => {
window.myServiceWorker = registration
})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 suggestion: ‏if we don't plan to use interactWithWorker in the coming tests, we could remove it and the window.myServiceWorker reference.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed, I kept the window.myServiceWorker to avoid double registering.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can this happen?

@mormubis mormubis force-pushed the adlrb/logs-improve-testing branch from 4a69138 to 762681a Compare October 23, 2025 13:55
@mormubis mormubis requested a review from bcaudan October 23, 2025 15:56
servers.base.bindServerApp(
createMockServerApp(servers, setup, {
remoteConfiguration: setupOptions.remoteConfiguration,
workerImplementation: setupOptions.workerImplementationFactory && workerSetup(setupOptions, servers),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 suggestion: ‏the check is also done inside the function, so we could probably remove it from here

Suggested change
workerImplementation: setupOptions.workerImplementationFactory && workerSetup(setupOptions, servers),
workerImplementation: workerSetup(setupOptions, servers),

@mormubis mormubis force-pushed the adlrb/logs-improve-testing branch from 10587ae to 1ea0c00 Compare November 3, 2025 16:54
@mormubis mormubis requested a review from bcaudan November 3, 2025 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants